window.addEventListener('load',function(){
    var transform=document.querySelector('.transform').querySelector('img');
    var password=document.querySelector('#password');
    var flag=0;
    transform.onclick=function(){
        if(flag==0){
            password.type='text'; 
            transform.src='images/open.png';
            flag=1;
        }else {
            password.type='password'; 
            transform.src='images/close.png';
            flag=0;
        }
    }
})

//自动登录
var old_token = window.localStorage.getItem("token");
if(old_token!=null)
{
    var data={
        "token":old_token
    }
    $.ajax({
        url:"/TokenCheck",
        type:"GET",
        data:data,
        dataType:"html",
        success:function (data){
            if(data.toString()=="true")
                window.location.href="/index?token="+old_token;
            // else
            //     alert("登录凭证过期");
        }
    })

}



LoginCheck = function (){
    var username = $("#username").val();
    var password = $("#password").val();

    var data ={
        "username":username,
        "password":password
    }

    $.ajax({
        url:"/loginCheck",
        type:"Post",
        data:data,
        dataType:"html",
        success:function (data)
        {
            if(data.toString().length>=20)
            {
                window.localStorage.setItem("token",data);
                window.location.href="/index?token="+data;
            }
            else {
                alert(data);
            }
        }
    });

}


        
